package com.chj.comp.common.core.config;

import io.minio.MinioClient;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ：cuihui
 * @date ：Created in 2023/1/12
 * @description：minio核心配置类
 * @modified By：
 */
@Configuration
//@EnableConfigurationProperties(MinioProp.class)
public class MinioConfig {

    @Autowired
    private MinioProp minioProp;

    /**
     * 获取 MinioClient
     * @return
     */
    @Bean
    public MinioClient minioClient() {
        if(StringUtils.isEmpty(minioProp.getEndpoint())){
            return null;
        }
        return MinioClient.builder()
                .endpoint(minioProp.getEndpoint())
                .credentials(minioProp.getAccesskey(), minioProp.getSecretKey())
                .build();
    }
}
